<?php
require_once("../global.inc.php");

class SysAttributeManage extends SystemFrameWork{
	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_attribute;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;

	function main(){
		/**
		 * 创建商品属性对象
		 */
		if (!is_object($this->obj_attribute)){
			require_once("attribute.class.php");
			$this->obj_attribute = new AttributeClass();
		}
		/**
		 * 创建商品属性内容对象
		 */
		if (!is_object($this->obj_attribute_content)){
			require_once("attribute_content.class.php");
			$this->obj_attribute_content = new AttributeContentClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}

		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("system");

		/**
		 * 语言包
		 */
		$this->getlang("attribute");

		switch ($this->_input['action']){
			case "list":
				$this->_listattribute();
				break;
			case "add":
				$this->_addattribute();
				break;
			case "save":
				$this->_saveattribute();
				break;
			case "modi":
				$this->_modiattribute();
				break;
			case "update":
				$this->_updateattribute();
				break;
			case "del":
				$this->_delattribute();
				break;
			default:
				$this->_listattribute();
				break;
		}

	}
	/**
	 * 取得属性列表
	 */
	function _listattribute(){

		require_once("productclass.class.php");
		$obj_product_category = new ProductCategoryClass();
		$ProductClassArray = $obj_product_category->listClassDetail($conditionstr,$Objpage);
		$pc_id = $this->_input['pcid'];
		$attribute_array = $this->obj_attribute->getAttributeList($pc_id);
		$attribute_content_array = $this->obj_attribute->getAttributeWithContentList($pc_id);
		$this->output("slPCategory", Common::showForm_Select2("slPCId", "", "onChange=window.location.href='attribute.manage.php?pcid='+this.options[this.selectedIndex].value+''", $ProductClassArray, $pc_id));
		$this->output("pc_id", $pc_id);
		$this->output("attribute_array", $attribute_array);
		$this->output("attribute_content_array", $attribute_content_array);
		$this->showpage("sys_attribute.manage");
	}

	/**
	 * 添加商品分类的属性
	 *
	 */
	function _addattribute(){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtAname"], "require"=>"true", "message"=>$this->_lang['errANameEmpty']),
		array("input"=>$this->_input["txtAtype"], "require"=>"true", "validator"=>"Number", "message"=>$this->_lang['errProductNameEmpty']),
		array("input"=>$this->_input["txtAorder"], "require"=>"true", "validator"=>"Number", "message"=>$this->_lang['errProductNameEmpty']));
		$error = $this->objvalidate->validate();

		if($error != ""){
			echo $error;
		}else{
			$result = $this->obj_attribute->addAttribute($this->_input);
			echo "ok";
		}
	}
	/**
	 * 更新商品分类的属性
	 * 
	 */
	function _updateattribute(){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["txtAname"], "require"=>"true", "message"=>$this->_lang['errANameEmpty']),
		array("input"=>$this->_input["txtAtype"], "require"=>"true", "validator"=>"Number", "message"=>$this->_lang['errAType']),
		array("input"=>$this->_input["txtAorder"], "require"=>"true", "validator"=>"Number", "message"=>$this->_lang['errAOrder']));
		$error = $this->objvalidate->validate();

		if($error != ""){
			echo $error;
		}else{
			$result = $this->obj_attribute->updateAttribute($this->_input);
			echo "ok";
		}
	}
	/**
	 * 删除商品分类的属性
	 *
	 */
	function _delattribute(){
		$this->_input['txtDelAid'] = split(',',$this->_input['txtAid']);
		//print_r($this->_input['txtDelAid']);
		$result = $this->obj_attribute->delAttribute($this->_input['txtDelAid']);
		echo "ok";
	}

}

$attribute_manage = new SysAttributeManage();
$attribute_manage->main();
unset($attribute_manage);
?>